import 'package:flutter/material.dart';

//Flutter 富文本
void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: SizedBox.expand(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Image.network(
                'https://q3.itc.cn/images01/20241220/ae5d3e42655147c4a184089cb6895c58.jpeg',
                width: 200,
                height: 200,

                cacheHeight: 400,
                cacheWidth: 400,

                fit: BoxFit.cover,
                alignment: Alignment.center,
                repeat: ImageRepeat.noRepeat,
                isAntiAlias: true,
                filterQuality: FilterQuality.high,

                //自定义头
                headers: {'token': 'iodajfasdfgsdagsg'},

                opacity: AlwaysStoppedAnimation(1),

                //加载中
                // loadingBuilder:
                //     (
                //       BuildContext context,
                //       Widget child,
                //       ImageChunkEvent? loadingProgress,
                //     ) {
                //       if (loadingProgress == null) {
                //         return child;
                //       }
                //
                //       if (loadingProgress.expectedTotalBytes != null) {
                //         var value =
                //             loadingProgress.cumulativeBytesLoaded /
                //             loadingProgress.expectedTotalBytes!;
                //         return CircularProgressIndicator(value: value);
                //       }
                //
                //       return CircularProgressIndicator();
                //     },
                frameBuilder:
                    (
                      BuildContext context,
                      Widget child,
                      int? frame,
                      bool wasSynchronouslyLoaded,
                    ) {
                      if (wasSynchronouslyLoaded) {
                        return child;
                      }

                      return AnimatedOpacity(
                        opacity: frame == null ? 0 : 1,
                        duration: Duration(milliseconds: 2000),
                        curve: Curves.ease,
                        child: child,
                      );
                    },

                errorBuilder:
                    (
                      BuildContext context,
                      Object error,
                      StackTrace? stackTrace,
                    ) {
                      return Container(
                        width: 200,
                        height: 200,
                        color: Colors.grey[300],
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Icon(Icons.image_not_supported_outlined, size: 30),
                          ],
                        ),
                      );
                    },
              ),

              Image.asset(
                'asset/images/anquanyinsi.png',
                width: 100,
                height: 100,
              ),
              Image.asset(
                'asset/images/quanqiukuajing.png',
                width: 200,
                height: 100,
                fit: BoxFit.none,
                scale: 0.9,
              ),
            ],
          ),
        ),
      ),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
